import React from 'react'
import PropTypes from 'prop-types'
import {Table} from 'antd'
import Link from 'umi/link'
import AnimTableBody from 'components/DataTable/AnimTableBody'


class List extends React.Component {

  constructor (props) {
    super(props)
    this.state = {
      list: [],
    }
  }

  render () {
    const {isMotion, ...tableProps} = this.props
    const {list} = this.state
    const columns = [
      {
        title: '序号',
        dataIndex: 'index',
        key: 'index',
        render: (v, r, i) => (i + 1),
      },
      {
        title: '运营微号',
        dataIndex: 'wxId',
        key: 'wxId',
      }, {
        title: '微信昵称',
        dataIndex: 'nickname',
        key: 'nickname',
      }, {
        title: '归属员工',
        dataIndex: 'belongEmpName',
        key: 'belongEmpName',
      }, {
        title: '部门',
        dataIndex: 'deptName',
        key: 'deptName',
      }, {
        title: '风控次数',
        dataIndex: 'count',
        key: 'count',
      },
    ]

    const childTablecolumns = [
      {
        title: '序号',
        dataIndex: 'index',
        key: 'index',
        render: (v, r, i) => (i + 1),
      },
      {
        title: '归属员工',
        dataIndex: 'belongEmpName',
        key: 'belongEmpName',
      },
      {
        title: '部门',
        dataIndex: 'department',
        key: 'department',
        render: (val) => val ? val.name : '-',
      },
      {
        title: '敏感类型',
        dataIndex: 'sensitiveName',
        key: 'sensitiveName',
      },
      {
        title: '操作时间',
        dataIndex: 'operationTime',
        key: 'operationTime',
      },
      {
        title: '查看详情',
        key: 'detail',
        render: () => <Link to={'#'}>详情</Link>,
      },
    ]

    const ChildTable = (record) => {
      return (
        <Table columns={childTablecolumns} rowKey={record.wxId} pagination={false} dataSource={record.riskList}/>
      )
    }


    const AnimateBody = (props) => {
      return <AnimTableBody {...props} />
    }

    const CommonBody = (props) => {
      return <tbody {...props} />
    }

    return (
      <Table
        {...tableProps}
        scroll={{x: 1500}}
        columns={columns}
        expandedRowRender={ChildTable}
        simple
        rowKey={record => record.id}
        components={{
          body: {wrapper: isMotion ? AnimateBody : CommonBody},
        }}
      />
    )
  }
}

List.propTypes = {
  onDeleteItem: PropTypes.func,
  onEditItem: PropTypes.func,
  isMotion: PropTypes.bool,
  location: PropTypes.object,
}

export default List
